import time
import random
import logging
from pathlib import Path

# 确保日志目录存在
Path("logs").mkdir(exist_ok=True)

logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        # logging.FileHandler('logs/app.log'),  # 注释此行移除文件日志
        logging.StreamHandler()
    ]
)

messages = [
    "用户登录成功", 
    "数据查询开始",
    "API请求耗时 250ms",
    "内存使用率 65%",
    "数据库连接池活跃连接数: 8"
]

while True:
    log_msg = random.choice(messages)
    logging.info(log_msg)
    time.sleep(random.uniform(0.5, 2))